package com.example.lotterybackend.dao.mapper;

import com.example.lotterybackend.dao.dataobject.PhoneNumberEncrypt;
import com.example.lotterybackend.dao.dataobject.UserDO;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {
    @Select("select count(*) from user where email = #{email}")
    int countByMail(@Param("email") String email);

    @Select("select count(*) from user where phone_number = #{phoneNumber}")
    int countByPhone(@Param("phoneNumber") PhoneNumberEncrypt phoneNumber);

    @Insert("insert into user (user_name, email, phone_number, password, identity) values" +
            " (#{userName}, #{email}, #{phoneNumber}, #{password}, #{identity})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insertUser(UserDO userDO);

    @Select("select * from user where id = #{id}")
    UserDO findById(@Param("id") Long id);

    @Select("select * from user where phone_number = #{phoneNumber}")
    UserDO selectByPhoneNumber(@Param("phoneNumber") PhoneNumberEncrypt phoneNumber);

    @Select("select * from user where email = #{email}")
    UserDO selectByMail(@Param("email") String email);
}
